<?php

namespace catchAdmin\phone\controller;

//use catchAdmin\phone\model\Order;
use catchAdmin\phone\model\Vruser;
use catchAdmin\vr\enum\EnumPrice;
use think\facade\Log;
use think\facade\Db;

class Orderno
{
    public function index()
    {
        $params = file_get_contents("php://input");
        $objectxml = (array)simplexml_load_string($params, 'SimpleXMLElement', LIBXML_NOCDATA);


        if (isset($objectxml)) {

            $orderid = Db::name('zhifulog')->where('zhifuorder', $objectxml['out_trade_no'])->value('orderid');

            Db::transaction(function () use($orderid,$objectxml){
                Db::name('zhifulog')->where('zhifuorder', $objectxml['out_trade_no'])->update([
                    'status' => 1,
                ]);
                Db::name('order')->where(
                    'order', $orderid
                )->update([
                    'status' => 1,
                ]);
                $num = $objectxml['total_fee'] / 6000;

                Db::name('shidai')->where('openid',$objectxml['openid'])->inc('kcnum',$num)->update();
//                return '<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>';
            });



        } else {
            echo false;
            exit;
        }
        $mes=array(
            'return_code'=>'SUCCESS',
            'return_msg'=>'OK'
        );
        return xml($mes);

    }

    public function vip(){
        $params = file_get_contents("php://input");
        $objectxml = (array)simplexml_load_string($params, 'SimpleXMLElement', LIBXML_NOCDATA);
        Log::write('dddd',json_encode($objectxml));
        Log::write('eeee','123123123');
        if (isset($objectxml)) {

            $orderid = Db::name('zhifulog')->where('zhifuorder', $objectxml['out_trade_no'])->value('orderid');

            Db::transaction(function () use($orderid,$objectxml){
                Db::name('zhifulog')->where('zhifuorder', $objectxml['out_trade_no'])->update([
                    'status' => 1,
                ]);
                Db::name('order')->where(
                    'order', $orderid
                )->update([
                    'status' => 1,
                ]);


//                Db::name('shidai')->where('openid',$objectxml['openid'])->inc('kcnum',$num)->update();
                Vruser::where('openid',$objectxml['openid'])->update([
                    'vip'=>1
                ]);
//                return '<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>';
            });

        } else {
            echo false;
            exit;
        }
        $mes=array(
            'return_code'=>'SUCCESS',
            'return_msg'=>'OK'
        );
        return xml($mes);
    }

}